package com.xxxx.ssm;

import com.xxxx.ssm.exception.BusinessException;
import com.xxxx.ssm.exception.ParamsException;
import org.springframework.web.bind.annotation.ExceptionHandler;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * 父类：页面处理器需要继承父类(父类中处理异常的方法需要添加注解)
 */
public class BaseController {

    @ExceptionHandler
    public String exec(HttpServletRequest request , HttpServletResponse response , Exception ex){
        request.setAttribute("ex" , ex);
        //自定义异常
        if(ex instanceof ParamsException){
            return "params_error";
        }
        if(ex instanceof BusinessException){
            return "business_error";
        }
        return "error";
    }
}
